package cn.jinjimi.app.services;

import android.app.IntentService;
import android.content.Intent;
import android.os.IBinder;

import cn.jinjimi.base.preference.PreferenceManager;
import cn.jinjimi.domain.ServiceManager;
import cn.jinjimi.domain.store.FileStore;
import cn.jinjimi.app.entity.Avatar;
import cn.jinjimi.app.modules.notify.NotificationDispatcher;
import cn.jinjimi.app.bean.SharePrefKeys;

import java.io.File;
import java.util.concurrent.Callable;

import bolts.Continuation;
import bolts.Task;

/**
 * Created by Jinsen on 2015/6/24.
 */
public class UploadService extends IntentService {

    String TAG = "UploadService";

    public static final int UPLOAD_FAIL = 3;
    public static final int UPLOAD_SUCCESS = 2;
    public static final int UPLOAD_PROCESSING = 1;
    public static final int UPLOAD_EMPTY = 0;

    String mFilePath = null;

    public UploadService() {
        this("");
    }

    public UploadService(String name) {
        super(name);
    }

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        mFilePath = intent.getStringExtra("filePath");
        uploadFile();
    }


    @Override
    public void onCreate() {
        super.onCreate();
    }


    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {

        return super.onStartCommand(intent, flags, startId);
    }


    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    private void uploadFile() {

        Intent it = new Intent(NotificationDispatcher.PHOTO_UPLOAD_STATE_ACTION);
        it.putExtra("state", UPLOAD_PROCESSING);
        sendBroadcast(it);

        PreferenceManager.setData(
                SharePrefKeys.PREF_PERSONAL_PHOTO_UPLOAD_STATE,
                UPLOAD_PROCESSING
        );

    }

}
